package com.zsw.procure_system.controller;

import com.alibaba.fastjson2.JSONObject;
import com.zsw.procure_system.pojo.Vo.DataCountVo;
import com.zsw.procure_system.pojo.Vo.OrderInfoVo;
import com.zsw.procure_system.pojo.result.ApiResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.io.InputStream;

@RestController
@Slf4j
@CrossOrigin
@RequestMapping("/home")
public class HomeController {

    @GetMapping("/dataCount")
    public ApiResult<DataCountVo> getDataCount() {
        return ApiResult.ok(new DataCountVo(1, 63595, 19276, 86258, 53935, 329238, 1228, 75641, 9583));
    }

    @GetMapping("/orderInfo")
    public ApiResult<OrderInfoVo> getOrderInfo() {
        return ApiResult.ok(new OrderInfoVo(82131, 122, 43451, 332, 12412, 342, "", ""));
    }

    @GetMapping("/format")
    public ApiResult<JSONObject> format() throws IOException {
        InputStream resourceAsStream = this.getClass().getResourceAsStream("/json/format.json");
        String s = IOUtils.toString(resourceAsStream);
        JSONObject jsonObject = JSONObject.parseObject(s);
        return ApiResult.ok(jsonObject);
    }
}
